package com.qqt.csr.im.utils;

import com.corundumstudio.socketio.SocketIOClient;
import com.qqt.csr.common.utils.CacheKeyUtil;
import com.qqt.csr.im.entity.Connection;

/**
 * @Author: yang hao
 * @Date: 2024/10/15 15:26
 * @Description: 设备缓存key工具类
 **/
public class DeviceCacheKeyUtil {

    /**
     * 获取设备key
     * @param client {@link SocketIOClient} socket客户端
     * @return {@link String} 键
     */
    public static String getKey(SocketIOClient client) {
        Long accountId = client.get("accountId");
        String deviceFlag = client.get("deviceFlag");
        String deviceType = client.get("deviceType");
        // 拼凑key
        return String.format(CacheKeyUtil.IM.CONNECT, accountId, deviceFlag, deviceType);
    }

    /**
     * 获取设备key
     * @param connection {@link Connection} 人员信息
     * @return {@link String} 键
     */
    public static String getKey(Connection connection) {
        // 拼凑key
        return String.format(CacheKeyUtil.IM.CONNECT, connection.getAccountId(), connection.getDeviceFlag(), connection.getDeviceType().toString());
    }

}
